import Express from "express"
import { addComServ, delComServ, getComByIdsPageServ, getComByPageServ, updateComServ } from "../Service/commentServ.js"


export const commentRouter = Express.Router()

commentRouter.post('/', async(req,res) => {
    const result = await addComServ(req.body)
    res.json(result)
})
commentRouter.delete('/:id', async (req,res) => {
    const result = await delComServ(req.params.id)
    res.json(result)
})
commentRouter.put('/:id', async (req,res) => {
    const id = req.params.id
    const obj = req.body
    const result = await updateComServ(id,obj);
    res.json(result)
})
commentRouter.get('/all', async(req,res) => {
    const {page, size} = req.query
    const result = await getComByPageServ(page, size)
    res.json(result)
})
commentRouter.get('/:id', async(req,res)=>{
    const {page, size} = req.query
    const id = req.params.id
    const result = await getComByIdsPageServ(id,page,size)
    res.json(result)
})